#include "display.h"

CDisplay::CDisplay(void)
{}

CDisplay::~CDisplay(void)
{}

void CDisplay::parseMessage(Message& msg, vector<Message>& retMsg)
{
	switch(msg.MsgCode)
	{
	case MSG_INIT:
		{	// Display size is passed using CCoords
			//PCoords c = dynamic_pointer_cast<CCoords>(msg.Data);
			//display = make_shared<CArray2D>(c->getX(),c->getY());
			display = make_shared<CArray2D>(10,10);
			for(int i=0; i<10; i++)
				for(int j=0; j<10; j++)
					(*display)(i,j)=' ';
		}
		break;
	case MSG_UPDATE:
		break;
	case MSG_DRAW:
		{
			for(int i=0; i<10; i++)
				for(int j=0; j<10; j++)
					(*display)(i,j)=' ';
			Message m;
			m.Set("Display","All",MSG_DRAW_L2, display);
			retMsg.push_back(m);
			m.Set("Display","All",MSG_DRAW_L1, display);
			retMsg.push_back(m);
			m.Set("Display","All",MSG_DRAW_L0, display);
			retMsg.push_back(m);
			m.Set("Display","Display",MSG_REFRESH_DISPL);
			retMsg.push_back(m);
		}
		break;
	case MSG_REFRESH_DISPL:
		{
			system("cls");
			for(int j=display->getYsize()-1; j>=0; j--)
			{
				for(int i=0; i<display->getXsize(); i++)
					cout << static_cast<char>( (*display)(i,j) );
				cout << endl;
			}
		}
		break;
	}
}